#coding=UTF-8
from PyQt4 import QtCore, QtGui
import IC_DefineLibrary

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    def _fromUtf8(s):
        return s

try:
    _encoding = QtGui.QApplication.UnicodeUTF8
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig)

class Ui_Modify_Dialog(QtGui.QMainWindow): #object    
    def setupUi2(self):
        QtGui.QWidget.__init__(self)
        self.setObjectName(_fromUtf8("Dialog")) #Dialog
        self.setGeometry(QtCore.QRect(60, 60, 500, 260))
        self.resize(500, 330)
        self.frame_9 = QtGui.QFrame(self)
        self.frame_9.setGeometry(QtCore.QRect(0, 0, 500, 330))
        self.frame_9.setFrameShape(QtGui.QFrame.StyledPanel)
        self.frame_9.setFrameShadow(QtGui.QFrame.Raised)
        self.frame_9.setObjectName(_fromUtf8("frame_9"))
        self.frame_10 = QtGui.QFrame(self.frame_9)
        self.frame_10.setGeometry(QtCore.QRect(0, 0, 500, 70))
        self.frame_10.setFrameShape(QtGui.QFrame.StyledPanel)
        self.frame_10.setFrameShadow(QtGui.QFrame.Raised)
        self.frame_10.setObjectName(_fromUtf8("frame_10"))
        self.label_8 = QtGui.QLabel(self.frame_10)
        self.label_8.setGeometry(QtCore.QRect(0, 0, 500, 70))
        font = QtGui.QFont()
        font.setFamily(_fromUtf8("Arial"))
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.label_8.setFont(font)
        self.label_8.setFrameShape(QtGui.QFrame.StyledPanel)
        self.label_8.setAlignment(QtCore.Qt.AlignCenter)
        self.label_8.setObjectName(_fromUtf8("label_8"))
        self.frame_11 = QtGui.QFrame(self.frame_9)
        self.frame_11.setGeometry(QtCore.QRect(0, 70, 500, 240))
        self.frame_11.setFrameShape(QtGui.QFrame.StyledPanel)
        self.frame_11.setFrameShadow(QtGui.QFrame.Raised)
        self.frame_11.setObjectName(_fromUtf8("frame_11"))
        self.label_9 = QtGui.QLabel(self.frame_11)
        self.label_9.setGeometry(QtCore.QRect(90, 30, 100, 30))
        font = QtGui.QFont()
        font.setFamily(_fromUtf8("Arial"))
        font.setPointSize(9)
        font.setBold(True)
        font.setWeight(75)
        self.label_9.setFont(font)
        self.label_9.setAlignment(QtCore.Qt.AlignCenter)
        self.label_9.setObjectName(_fromUtf8("label_9"))
        self.label_10 = QtGui.QLabel(self.frame_11)
        self.label_10.setGeometry(QtCore.QRect(90, 80, 100, 30))
        font = QtGui.QFont()
        font.setFamily(_fromUtf8("Arial"))
        font.setPointSize(9)
        font.setBold(True)
        font.setWeight(75)
        self.label_10.setFont(font)
        self.label_10.setAlignment(QtCore.Qt.AlignCenter)
        self.label_10.setObjectName(_fromUtf8("label_10"))
        self.textEdit_4 = QtGui.QTextEdit(self.frame_11)
        self.textEdit_4.setGeometry(QtCore.QRect(190, 30, 200, 30))
        font = QtGui.QFont()
        font.setFamily(_fromUtf8("Arial"))
        font.setPointSize(9)
        self.textEdit_4.setFont(font)
        self.textEdit_4.setTabChangesFocus(True)
        self.textEdit_4.setObjectName(_fromUtf8("textEdit_4"))
        self.lineEdit_3 = QtGui.QLineEdit(self.frame_11)
        self.lineEdit_3.setGeometry(QtCore.QRect(190, 80, 200, 30))
        self.lineEdit_3.setEchoMode(QtGui.QLineEdit.Password)
        self.lineEdit_3.setObjectName(_fromUtf8("lineEdit_3"))
        self.lineEdit_4 = QtGui.QLineEdit(self.frame_11)
        self.lineEdit_4.setGeometry(QtCore.QRect(190, 130, 200, 30))
        self.lineEdit_4.setEchoMode(QtGui.QLineEdit.Password)
        self.lineEdit_4.setObjectName(_fromUtf8("lineEdit_4"))
        self.label_11 = QtGui.QLabel(self.frame_11)
        self.label_11.setGeometry(QtCore.QRect(85, 125, 100, 40))
        font = QtGui.QFont()
        font.setFamily(_fromUtf8("Arial"))
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.label_11.setFont(font)
        self.label_11.setAlignment(QtCore.Qt.AlignCenter)
        self.label_11.setObjectName(_fromUtf8("label_11"))
        self.pushButton_7 = QtGui.QPushButton(self.frame_11)
        self.pushButton_7.setGeometry(QtCore.QRect(190, 190, 80, 30))
        font = QtGui.QFont()
        font.setFamily(_fromUtf8("Arial"))
        font.setBold(True)
        font.setWeight(75)
        self.pushButton_7.setFont(font)
        self.pushButton_7.setObjectName(_fromUtf8("pushButton_7"))
        QtCore.QObject.connect(self.pushButton_7, QtCore.SIGNAL("clicked()"),self.SubmitData1)
        self.pushButton_8 = QtGui.QPushButton(self.frame_11)
        self.pushButton_8.setGeometry(QtCore.QRect(295, 190, 80, 30))
        font = QtGui.QFont()
        font.setFamily(_fromUtf8("Arial"))
        font.setBold(True)
        font.setWeight(75)
        self.pushButton_8.setFont(font)
        self.pushButton_8.setObjectName(_fromUtf8("pushButton_8"))
        QtCore.QObject.connect(self.pushButton_8, QtCore.SIGNAL("clicked()"),self.close )
        self.frame_12 = QtGui.QFrame(self.frame_9)
        self.frame_12.setGeometry(QtCore.QRect(0, 310, 500, 20))
        self.frame_12.setFrameShape(QtGui.QFrame.StyledPanel)
        self.frame_12.setFrameShadow(QtGui.QFrame.Plain)
        self.frame_12.setObjectName(_fromUtf8("frame_12"))
        
        self.retranslateUi()
        QtCore.QMetaObject.connectSlotsByName(self)
        IC_DefineLibrary.MessageBox(title='Notes',message='Please modiy your Username and Old\New Password infomation, then submit them to database !')

    def retranslateUi(self):  #Dialog
        self.setWindowTitle(_translate("Dialog", "Information Centre", None))
        self.label_8.setText(_translate("Dialog", "Information Centre", None))
        self.label_9.setText(_translate("Dialog", "Username", None))
        self.label_10.setText(_translate("Dialog", "Old Password", None))
        self.label_11.setText(_translate("Dialog", "New Password", None))
        self.pushButton_7.setText(_translate("Dialog", "Submit", None))
        self.pushButton_8.setText(_translate("Dialog", "Close", None))

    def SubmitData1(self):
        if self.textEdit_4.toPlainText()=='' or self.lineEdit_3.text()=='' or self.lineEdit_4.text()=='':
            return IC_DefineLibrary.MessageBox(title='Notes',message='Please input your username, old password and new password integrallty !')
        dbo5=IC_DefineLibrary.DB_Operating(sql="Select Username,Password from Login")
        te3=self.textEdit_4.toPlainText()
        le2=self.lineEdit_3.text()
        le3=self.lineEdit_4.text()
        flag=0
        for (Username, Password) in dbo5.row:
            if te3==Username and le2==Password:
                if le2==le3:
                    self.lineEdit_4.clear()
                    return IC_DefineLibrary.MessageBox(title='Notes',message='You have input the same password with old password, please try again !')
                dbo6=IC_DefineLibrary.DB_Operating(sql="update Login set Password = '"+'%s'%le3+"'"+" where Username= '"+'%s'%te3+"'")
                flag=1
                self.textEdit_4.setPlainText("")
                self.lineEdit_3.clear()
                self.lineEdit_4.clear()
                return IC_DefineLibrary.MessageBox(title='Notes',message='You have changed your new password successfully !')
        if flag==0:
            self.textEdit_4.setPlainText("")
            self.lineEdit_3.clear()
            self.lineEdit_4.clear()
            return IC_DefineLibrary.MessageBox(title='Notes',message='You have input wrong Username and\or Password, please check your data connection and Old user information, then try again !')

